﻿#! python3
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from shutil import copyfile
from sys import exit

from file_ext import file_name_make, fil_add_suffix
import os

import time

localtime = time.localtime(time.time())

# 源文件和目标文件路径，前缀每个‘.’代表目录上移一级
srcdir = '/ObjApp'
old_filename = ['PTUT_APP_SRC.hex', 'PTUT_APP_SRC.bin']
desdir = '/publish'
new_filename = ['PTUT_APP_SRC.hex', 'PTUT_APP_SRC.bin']

# 获取当前时间
dt = localtime.tm_year.__str__()
if localtime.tm_mon < 10:
    dt += '0'
dt += localtime.tm_mon.__str__()
if localtime.tm_mday < 10:
    dt += '0'
dt += localtime.tm_mday.__str__()
dt += '.'
if localtime.tm_hour < 10:
    dt += '0'
dt += localtime.tm_hour.__str__()
if localtime.tm_min < 10:
    dt += '0'
dt += localtime.tm_min.__str__()

# 获取当前路径
path = os.getcwd()

print("py3-> bulid end， copy bin")

index = 0
while index < old_filename.__len__():
    # 创建路径字符串
    desfile = desdir + '/' + fil_add_suffix(new_filename[index], dt)
    srcfile = srcdir + '/' + old_filename[index]
    index += 1
    path_src = file_name_make(path, srcfile)
    path_des = file_name_make(path, desfile)

    # 输出信息
    print("py3-> copy file %s \npy3-> to        %s" % (path_src, path_des))

    # copy 文件
    try:
        copyfile(path_src, path_des)
    except IOError:
        print("py3-> copy error")
    else:
        print("py3-> copy ok")

exit(0)

